using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml;

using vs.Core;
using vs.Paging;
using vs.Authentication;

namespace Forum
{
    public partial class topic_lastest : Window
    {
        public const string CACHE_LATEST_TOPIC = "CACHE_LATEST_TOPIC";
        private XmlDocument GenList()
        {
            object o = DataCache.GetCache(CACHE_LATEST_TOPIC);
            if (o != null) return (XmlDocument)o;

            string topicdesk = this.GetModuleSetting("topicdesk");
            if (topicdesk != "")
            {
                engine_xml engine = new engine_xml();
                XmlDocument doc = engine.LastestTopicXML(topicdesk);

                DataCache.SetCache(CACHE_LATEST_TOPIC, doc);
                return doc;
            }
            else
            {
                Response.Write("Quan tri he thong phai dat lai thong so 'topicdesk'");
            }

            return null;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (!Page.IsPostBack)
                {
                    XmlDocument doc = GenList();
                    if (doc != null)
                    {
                        string skin = ModSettingController.GetModuleSetting("skin", Utils.ModuleID);
                        string template = engine_xml.get_template_folder(skin) + "forum_lastest.xsl";
                        CommonFunction.XMLTransform(xmlTransformer, template, doc);
                    }
                }
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }
        }
    }
}